//
//  OosService.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 3/22/11.
//

#import <oos4ios/Model/OosService.h>
#import <oos4ios/Oos4ios.h>
#import <oos4ios/Model/OosReview.h>


@implementation OosService

@dynamic name;
@dynamic reviewSnippet;
@dynamic privacy;

static NSString *fetchPredicate = @"slug = %@";

+ (OosService *) serviceFromSlug: (NSString *) slug
{
    OosService *result = nil;
    if (slug) {
        result = [super objectWithPredicate:fetchPredicate, slug];
    }
    if (!result) {
		result = [super create];
		result.slug = slug;
	}
	return result;
}

@dynamic categories;
@dynamic attributes;
@dynamic permalink;
@dynamic serviceUrlString;
@dynamic mediaUrlString;
@dynamic urlString;
@dynamic leadServiceUrlString;
@dynamic oosId;
@dynamic slug;
@dynamic telephone;
@dynamic reviewCount;
@dynamic savedCount;
@dynamic rating;
@dynamic location;
@dynamic myReview;
@dynamic users;
@dynamic savedBy;
@dynamic tags;

- (NSURL *)url
{
    NSString *url = [self urlString];
    if (url) {
        return [NSURL URLWithString:url];
    } else {
        return nil;
    }
}

- (void)setUrl:(NSURL *)url
{
    if (!url) {
        self.urlString = nil;
    } else {
        self.urlString = url.absoluteString;
    }
}

#pragma meadiaUrl

- (NSURL *)mediaUrl
{
    NSString *url = [self mediaUrlString];
    if (url) {
        return [NSURL URLWithString:url];
    } else {
        return nil;
    }
}

- (void)setMediaUrl:(NSURL *)url
{
    if (!url) {
        self.mediaUrlString = nil;
    } else {
        self.mediaUrlString = url.absoluteString;
    }
}

#pragma leadServiceUrl

- (NSURL *)leadServiceUrl
{
    NSString *url = [self leadServiceUrlString];
    if (url) {
        return [NSURL URLWithString:url];
    } else {
        return nil;
    }
}

- (void)setLeadServiceUrl:(NSURL *)url
{
    if (!url) {
        self.leadServiceUrlString = nil;
    } else {
        self.leadServiceUrlString = url.absoluteString;
    }
}

#pragma serviceUrl

- (NSURL *)serviceUrl
{
    NSString *url = [self leadServiceUrlString];
    if (url) {
        return [NSURL URLWithString:url];
    } else {
        return nil;
    }
}

- (void)setServiceUrl:(NSURL *)url
{
    if (!url) {
        self.leadServiceUrlString = nil;
    } else {
        self.leadServiceUrlString = url.absoluteString;
    }
}

- (OosService *)oosService
{
    return self;
}

- (void)setOosService:(OosService *)oosService
{
//    self = oosService;
}


@end
